/**
 * Copyright © 2008, EMC Corporation.
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 *
 *     + Redistributions of source code must retain the above copyright notice, 
 *       this list of conditions and the following disclaimer.
 *     + Redistributions in binary form must reproduce the above copyright 
 *       notice, this list of conditions and the following disclaimer in the 
 *       documentation and/or other materials provided with the distribution.
 *     + The name of EMC Corporation may not be used to endorse or promote 
 *       products derived from this software without specific prior written 
 *       permission.
 *
 *      THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
 *      "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 
 *      TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
 *      PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 
 *      BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 *      CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 *      SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
 *      INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 *      CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 *      ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 *      POSSIBILITY OF SUCH DAMAGE.
 */
package com.emc.esu.api {
	import flash.events.Event;
	
	/**
	 * This class defines a state object that is passed to all of the EsuApi's
	 * callbacks.  It contains information about the method called and whether
	 * the call was successful.  If the call failed, the error information will
	 * be included.  The object also contains the user-defined state object that
	 * is passed to the methods.
	 */
	public class EsuCallbackState extends Event {
		private var _stateObject:Object;
		private var _successful:Boolean;
		private var _error:EsuError;
		private var _method:String;
		private var _result:Object;
		private var _esu:EsuApi;
		private var _token:String;
		
		/**
		 * Creates a new callback state object.
		 * @param esu the EsuApi object that was used for the method call.
		 * @param method the method that was called.
		 * @param successful whether the method call was successful.
		 * @param error the error (if any) that occurred during the call.
		 * @param stateObject the user-defined state object that was passed to the method
		 * @param result the result of the method.  If the method does not return a value, this will be null.
		 */
		public function EsuCallbackState( esu:EsuApi, method:String, successful:Boolean, error:EsuError, stateObject:Object, result:Object = null ) {
			super( "ESU_CALLBACK_STATE" );
			this._esu = esu;
			this._result = result;
			this._method = method;
			this._successful = successful;
			this._error = error;
			this._stateObject = stateObject;
		}
		
		/**
		 * Gets the EsuApi object used to make the call.
		 * @return the EsuApi object.
		 */
		public function getEsuApi():EsuApi {
			return _esu;
		}
		
		/**
		 * Gets the result of the method.  If the method does not return
		 * a value, this will be set to null.
		 */
		public function getResult():Object {
			return _result;
		}
		
		/**
		 * Gets the method that was called
		 * @return the method called.
		 */
		public function getMethod():String {
			return _method;
		}
		
		/**
		 * Returns true if the method was successful.  If the
		 * method failed, the error can be found by calling getError().
		 * @return true if the method was successful.
		 */
		public function wasSuccessful():Boolean {
			return _successful;
		} 
		
		/**
		 * Gets the error if the method failed.  If the method
		 * was successful, this will return null.
		 * @return the error that caused the method to fail.
		 */
		public function getError():EsuError {
			return _error;
		}
		
		/**
		 * Gets the user-defined state object that was passed
		 * to the method.
		 * @return the user-defined state object.
		 */
		public function getStateObject():Object {
			return _stateObject;
		}
		
		public function get esu():EsuApi {
			return _esu;
		}
		
		public function get result():Object {
			return _result;
		}
		
		public function get method():String {
			return _method;
		}
		
		public function get successful():Boolean {
			return _successful;
		}
		
		public function get error():EsuError {
			return _error;
		}
		
		public function get stateObject():Object {
			return _stateObject;
		}
		
		/**
		 * Continuation token from some methods
		 */
		public function get token():String {
			return _token;
		}

	}
}